package com.tedu.servies;

import com.tedu.dao.InforNewsMapper;
import com.tedu.pojo.Information;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 服务层接口实现类
 * 交给spring管理
 */
@Service
public class InforNewsServiesImpl implements InforNewsServies {

    @Autowired  //通过注解从spring容器取出
   private InforNewsMapper mapper;


    @Override
    public List<Information> getInformationByType(int type, int currentpage) {
        if (type<=0){
            return new ArrayList<>();
        }
        if(currentpage<=0){
            currentpage = 1;
        }
        return mapper.getInformationByType(type,(currentpage-1)*20);
    }



    @Override
    public int getCountByType(int topicID) {
        int count = mapper.getInformationCountByType(topicID);
        return count%20==0 ? count/20 : count/20+1;//  三目运算
    }


    @Override
    public Information getInformationById(int inforId) {

        //阅读新闻后，更新  该新闻的阅读量
        return mapper.getInformationById(inforId);
    }

    /**
     * 获取  size  最新的党建信息数据
     * @param i
     * @param size
     * @return
     */
    @Override
    public List<Information> getInformationByTypeTen(int i, int size) {
        if(size<=0){
            return new ArrayList<>();
        }
        return mapper.getInformationByTypeTen(i,size);
    }
}
